package com.laima.basic.controller;

import com.laima.basic.Exception.Response;
import com.laima.basic.model.SysDictData;
import com.laima.basic.model.SysMenu;
import com.laima.basic.service.SysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @program: backend-server
 * @description: 字典数据控制层
 * @author: T
 * @create: 2021-03-30 11:18
 **/

@Api(tags = {"数据字典管理"})
@RestController
@RequestMapping("sysDictData")
public class SysDictDataController {
    @Autowired
   private SysDictDataService sysDictDataService;

    private Logger logger =  LoggerFactory.getLogger(SysMenuController.class);


    @ApiOperation(value = "selectDictDataList", notes = "根据id查询 ")
    @RequestMapping(value = "selectDictDataList", method = RequestMethod.POST)
    public Response selectDictDataList(@RequestBody(required=false) SysDictData sysDictData) {
        return Response.ok(sysDictDataService.selectDictDataList(sysDictData));
    }

    @ApiOperation(value = "selectDictDataByType", notes = "根据类型查询 ")
    @RequestMapping(value = "selectDictDataByType", method = RequestMethod.GET)
    public Response selectDictDataByType(@RequestParam("dictType") String dictType) {
        return Response.ok(sysDictDataService.selectDictDataByType(dictType));
    }


    @ApiOperation(value = "selectDictLabel", notes = "根据字典类型和字典键值查询字典数据信息 ")
    @RequestMapping(value = "selectDictLabel", method = RequestMethod.GET)
    public Response selectDictLabel(@RequestParam("dictType") String dictType,@RequestParam("dictType") String dictValue) {
        return Response.ok(sysDictDataService.selectDictLabel(dictType, dictValue));
    }



    @ApiOperation(value = "selectDictDataById", notes = "根据字典数据ID查询信息 ")
    @RequestMapping(value = "selectDictDataById", method = RequestMethod.GET)
    public Response selectDictDataById(@RequestParam("dictCode") Long dictCode) {
        return Response.ok(sysDictDataService.selectDictDataById(dictCode));
    }

    @ApiOperation(value = "countDictDataByType", notes = "查询字典数据 ")
    @RequestMapping(value = "countDictDataByType", method = RequestMethod.GET)
    public Response countDictDataByType(@RequestParam("dictType") String dictType) {
        return Response.ok(sysDictDataService.countDictDataByType(dictType));
    }

    @ApiOperation(value = " insertDictData", notes = "新增字典数据信息 ")
    @RequestMapping(value = " insertDictData", method = RequestMethod.POST)
    public Response insertDictData(@RequestBody  SysDictData sysDictData) {
        return Response.ok(sysDictDataService.updateDictData(sysDictData));
    }


    @ApiOperation(value = " updateDictData", notes = "修改字典数据信息 ")
    @RequestMapping(value = " updateDictData", method = RequestMethod.POST)
    public Response updateDictData(@RequestBody  SysDictData sysDictData) {
        return Response.ok(sysDictDataService.updateDictData(sysDictData));
    }


    @ApiOperation(value = " deleteDictDataByIds", notes = "修改字典数据信息 ")
    @RequestMapping(value = " deleteDictDataByIds", method = RequestMethod.POST)
    public Response deleteDictDataByIds(@RequestParam("dictCode") Long[] dictCodes) {
        return Response.ok(sysDictDataService.deleteDictDataByIds(dictCodes));
    }



}
